cc.Class({
    extends: cc.Component,

    properties: {
        gameList: cc.Prefab,
        content: cc.Node,
        back: cc.Node,
        ScrollView: cc.ScrollView,
        i:0,
    },

    // use this for initialization
    onLoad: function () {
        this.backClick();
        this.ScrollViewEvent();
    },

    init(){
        if(this.content.childrenCount > 0) return ;
        this.show();
    },

    GameLisStorting(totalnum){
        this.bol = false;
        this.num = 0;
        for(this.i;this.i < cc.gameList.games.length; ){
            var ele = cc.gameList.games[this.i];
            this.i++
            this.add(ele);
            this.num ++;
            if(this.num >= totalnum){
                this.bol = true;
                return ;
            }
        }
    },

    ScrollViewEvent(){
        this.ScrollView.node.on("scroll-to-bottom", function(){
            if(this.bol){
               this.GameLisStorting(15);
            }
        }, this)
    },

    backClick(){
        this.back.on("click", function(){
            this.node.active = false;
        }, this)
    },

    show(){
        var self = this;
        if(cc.gameList.games){
             cc.gameList.games.sort(function(){
                return Math.random() - 0.5
            })
            this.GameLisStorting(15);
        }else{
            cc.gameList.loader(this) 
        }
    },

    add(data){
        var node = cc.instantiate(this.gameList);
        node.getComponent("Gamelist_moreGame").init(data);
        this.content.addChild(node);
    }

    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
});
